<%@ page language="java" session="true" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<script src="${pageContext.request.contextPath}/static/js/common/jquery-2.2.4.min.js"></script>
<html>
<body>
<h2>Hello World!</h2>
        Hello World!
<script>
    //设置ajax默认的complete函数和error函数，当后端返回响应码是500及以上的，就会进入error函数执行
    $.ajaxSetup({
        //在success之后执行，返回不为500及以上,
        complete: function (result) {
            console.log(0);
        },
        //返回码500及以上执行
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            debugger;
            console.log(3);
            console.log();
            console.log(XMLHttpRequest.responseJSON);
            if (XMLHttpRequest.status == 500) {
                //ajax请求
                result = XMLHttpRequest.responseJSON;
                console.log(result.code);
                alert(result.message);
            } else {
                //status=501
                //页面跳转请求
                location = "${pageContext.request.contextPath}/static/500.jsp";
            }
        },
        //在succss函数之前执行
        dataFilter: function (data, type) {
            console.log("in dataFilter");
            console.log(XMLHttpRequest);
            console.log(data);
            console.log(type);
            console.log(typeof arguments[0]);
        }
    });

    //在success之后执行，complete之前执行
    $(document).ajaxSuccess(function(){
        console.log("in ajaxSuccess")
    });

    $.ajax({
        type: "GET",
        dataType: "text",
        url: "${pageContext.request.contextPath}/getMenus",
        //返回码200执行
        success: function (data) {
            console.log(2);
        }
    });
</script>
</body>
</html>
